﻿Public Class Frm_NhanVienQuanLy

    Private Sub Frm_NhanVienQuanLy_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lbUserName.Text = Frm_Login.username + " (" + Frm_Login.acctype + ")"
        gvCaChieu_Load()
        gvQLSuatChieu_Load()
    End Sub

    'Quan lý ca chiếu
    '----------------------------------

    Public Sub gvCaChieu_Load()
        Dim bus As CaChieuBUS = New CaChieuBUS()
        gvCaChieu.DataSource = bus.GetTable("select * from CACHIEU")
    End Sub

    Private Sub btnThemCaChieu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemCaChieu.Click
        If (txtTimeEnd.Text = "" Or txtTimeStar.Text = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim cc As CaChieuDTO = New CaChieuDTO()
            Dim bus As CaChieuBUS = New CaChieuBUS()
            cc.MaCaChieu = qlMachieu.Text
            cc.GioBatDau = txtTimeStar.Text
            cc.GioKetThuc = txtTimeEnd.Text
            bus.Insert(cc)
            gvCaChieu_Load()
        End If
    End Sub

    Private Sub btnXoaCaChieu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaCaChieu.Click
        Dim bus As CaChieuBUS = New CaChieuBUS()
        Dim tmp As CaChieuDTO = New CaChieuDTO()
        tmp.MaCaChieu = qlMachieu.Text
        bus.Delete(tmp)
        gvCaChieu_Load()
    End Sub

    Private Sub btnSuaCaChieu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaCaChieu.Click
        If (txtTimeEnd.Text = "" Or txtTimeStar.Text = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim bus As CaChieuBUS = New CaChieuBUS()
            Dim cc As CaChieuDTO = New CaChieuDTO()
            cc.MaCaChieu = qlMachieu.Text
            cc.GioBatDau = txtTimeStar.Text
            cc.GioKetThuc = txtTimeEnd.Text
            bus.Update(cc)
            gvCaChieu_Load()
        End If
    End Sub

    Private Sub gvCaChieu_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvCaChieu.SelectionChanged
        Dim bus As CaChieuBUS = New CaChieuBUS()
        Try
            If gvCaChieu.SelectedRows.Count = 0 Then
                Return
            End If
            qlMachieu.Text = gvCaChieu.CurrentRow.Cells(0).Value.ToString()
            txtTimeStar.Text = gvCaChieu.CurrentRow.Cells(1).Value.ToString()
            txtTimeEnd.Text = gvCaChieu.CurrentRow.Cells(2).Value.ToString()
        Catch
        End Try
    End Sub



    'Quan ly suất chieu
    '___________________________________________________________

    Public Sub gvQLSuatChieu_Load()
        Dim bus As SuatChieuBUS = New SuatChieuBUS()
        gvQLSuatChieu.DataSource = bus.GetTable("select * from SUATCHIEU")
    End Sub


    Private Sub btnThemSC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemSC.Click
        If (cbxMaCaChieu.SelectedValue.ToString() = "" Or cbxTenPhim.SelectedValue.ToString() = "" Or cbxMaPhongChieu.SelectedValue.ToString() = "" Or txtGioBatDau.Text = "" Or txtGioKetThuc.Text = "" Or txtGiaVe.Text = "" Or dtpNgayChieu.Value.Date.ToString() = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim tmp As SuatChieuDTO = New SuatChieuDTO()
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            tmp.MaCaChieu = cbxMaCaChieu.SelectedValue.ToString()
            tmp.GioBatDau = txtGioBatDau.Text()
            tmp.GioKetThuc = txtGioKetThuc.Text()
            tmp.NgayChieu = dtpNgayChieu.Value.Date()
            tmp.TenPhim = cbxTenPhim.SelectedValue.ToString()
            tmp.MaPhongChieu = cbxMaPhongChieu.SelectedValue.ToString()
            tmp.GiaVe = txtGiaVe.Text()
            bus.Insert(tmp)
            gvQLSuatChieu_Load()
        End If
    End Sub

    Private Sub gvQLSuatChieu_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvQLSuatChieu.SelectionChanged
        Dim bus As SuatChieuBUS = New SuatChieuBUS()
        Try
            If gvQLSuatChieu.SelectedRows.Count = 0 Then
                Return
            End If

            txtMaSuatChieu.Text = gvQLSuatChieu.CurrentRow.Cells(0).Value.ToString()
            cbxMaCaChieu.Text = gvQLSuatChieu.CurrentRow.Cells(1).Value.ToString()
            txtGioBatDau.Text = gvQLSuatChieu.CurrentRow.Cells(2).Value.ToString()
            txtGioKetThuc.Text = gvQLSuatChieu.CurrentRow.Cells(3).Value.ToString()
            dtpNgayChieu.Value = gvQLSuatChieu.CurrentRow.Cells(4).Value
            cbxTenPhim.Text = gvQLSuatChieu.CurrentRow.Cells(5).Value.ToString()
            cbxMaPhongChieu.Text = gvQLSuatChieu.CurrentRow.Cells(6).Value.ToString()
            txtGiaVe.Text = gvQLSuatChieu.CurrentRow.Cells(7).Value.ToString()
        Catch
        End Try
    End Sub

    Private Sub btnXoaSC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaSC.Click

        Dim bus As SuatChieuBUS = New SuatChieuBUS()
        Dim tmp As SuatChieuDTO = New SuatChieuDTO()
        tmp.MaSuatChieu = txtMaSuatChieu.Text()
        bus.Delete(tmp)
        gvCaChieu_Load()
    End Sub

    Private Sub btnSuaSC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaSC.Click
        If (cbxMaCaChieu.SelectedValue.ToString() = "" Or cbxTenPhim.SelectedValue.ToString() = "" Or cbxMaPhongChieu.SelectedValue.ToString() = "" Or txtGioBatDau.Text = "" Or txtGioKetThuc.Text = "" Or txtGiaVe.Text = "" Or dtpNgayChieu.Value.Date.ToString() = "") Then
            MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo")
        Else
            Dim tmp As SuatChieuDTO = New SuatChieuDTO()
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            tmp.MaSuatChieu = txtMaSuatChieu.Text
            tmp.MaCaChieu = cbxMaCaChieu.SelectedValue.ToString()
            tmp.GioBatDau = txtGioBatDau.Text()
            tmp.GioKetThuc = txtGioKetThuc.Text()
            tmp.NgayChieu = dtpNgayChieu.Value.Date()
            tmp.TenPhim = cbxTenPhim.SelectedValue.ToString()
            tmp.MaPhongChieu = cbxMaPhongChieu.SelectedValue.ToString()
            tmp.GiaVe = txtGiaVe.Text()
            bus.Update(tmp)
            gvQLSuatChieu_Load()
        End If
    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        If (rbMaSuatChieu.Checked = True) Then
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            Dim str As String = "select * from SUATCHIEU where MaSuatChieu like '%" + txtsearch.Text + "%'"
            gvQLSuatChieu.DataSource = bus.GetTable(str)
        ElseIf (rbMaCaChieu.Checked = True) Then
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            Dim str As String = "select * from SUATCHIEU where MaCaChieu like '%" + txtsearch.Text + "%'"
            gvQLSuatChieu.DataSource = bus.GetTable(str)
        ElseIf (rbMaPhongChieu.Checked = True) Then
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            Dim str As String = "select * from SUATCHIEU where MaPhongChieu like '%" + txtsearch.Text + "%'"
            gvQLSuatChieu.DataSource = bus.GetTable(str)
        ElseIf (rbNgayChieu.Checked = True) Then
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            Dim str As String = "select * from SUATCHIEU where NgayChieu like '%" + txtsearch.Text + "%'"
            gvQLSuatChieu.DataSource = bus.GetTable(str)
        ElseIf (rbPhim.Checked = True) Then
            Dim bus As SuatChieuBUS = New SuatChieuBUS()
            Dim str As String = "select * from SUATCHIEU where TenPhim like '%" + txtsearch.Text + "%'"
            gvQLSuatChieu.DataSource = bus.GetTable(str)
        End If
    End Sub

    Private Sub cbxNgayChieu_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxNgayChieu.SelectedIndexChanged
        Dim bus As SuatChieuBUS = New SuatChieuBUS()
        Dim str As String = ""
        If (cbxNgayChieu.Text = "Tất cả") Then
            str = "select * from SUATCHIEU"
            gvQLSuatChieu.DataSource = bus.GetTable(str)
        Else
            str = "select * from SUATCHIEU where NgayChieu like '%" + cbxNgayChieu.Text + "%'"
            gvQLSuatChieu.DataSource = bus.GetTable(str)
        End If
    End Sub

    Private Sub lbUserName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbUserName.Click

    End Sub

    Private Sub lbDangXuat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbDangXuat.Click

        Frm_Login.txtTenDN.Text = ""
        Frm_Login.txtMatKhau.Text = ""
        Frm_Login.txtTenDN.Select()
        Close()
    End Sub
End Class